/* 386. 字典序排数 */
/**
 * @param {number} n
 * @return {number[]}
 */
var lexicalOrder = function (n) {
    const result = []
    let number = 1
    for (let i = 0; i < n; i++) {
        result.push(number)
        if (number * 10 <= n) {
            number *= 10

        } else {
            while (number % 10 === 9 || number + 1 > n) {
                number = Math.floor(number / 10)
            }
            number++
        }

    }
    console.log('result :>>', result);
};
var lexicalOrder = function (n) {
    const ret = []
    const dfs = (cur, n) => {
        if (cur > n) return
        ret.push(cur)
        for (let i = 0; i <= 9; i++) {
            const nextNum = cur * 10 + i
            if (nextNum > n) break
            dfs(nextNum, n)
        }
    }
    for (let i = 1; i <= 9; i++) {
        dfs(i, n)
    }
    return ret
};
const ret = lexicalOrder(15)
console.log('ret ;>>', ret);